
var flep_lightbox_id = 0;

function flep_lightbox() {
    var lb_id = flep_lightbox_id;
    flep_lightbox_id++;
    var div_blackbackground = CE("div");
    div_blackbackground.id = "blackbackground" + lb_id;
    div_blackbackground.style.display = 'block';
    A(div_blackbackground, 'class', 'blackbackground');
    AC(E('container'), div_blackbackground);
    var div_lightbox = CE("div");
    div_lightbox.id = "lightbox" + lb_id;
    A(div_lightbox, 'class', 'lightbox');
    AC(E('container'), div_lightbox);
    div_lightbox.style.display = 'inline-block';
    var div_close = CE("div");
    A(div_close, "class", "close");
    A(div_close, "onclick", "flep_lightbox_close(" + lb_id + ");");
    AC(div_lightbox, div_close);
    var img_close = CE("img");
    img_close.src = "request.php?res=close.png";
    A(img_close, "alt", "x");
    A(img_close, "tittle", "Close");
    AC(div_close, img_close);
    var div_scrolable = CE("div");
    A(div_scrolable, "class", "scrolable");
    div_scrolable.id = "scrolable" + lb_id;
    AC(div_lightbox, div_scrolable);
    return lb_id;
}

function flep_lightbox_close(lb_id) {
    E('blackbackground' + lb_id).style.display = 'none';
    E('lightbox' + lb_id).style.display = 'none';
    RC(E('container'), E('blackbackground' + lb_id));
    RC(E('container'), E('lightbox' + lb_id));
}

function flep_request_popup(page, post, width, height, headers){
    var ld_id = flep_lightbox();
    A(E('lightbox' + ld_id), 'style', A(E('lightbox' + ld_id), 'style') + " width: " + width  + "px; height: " + height + "px; margin-top: -" + (height/2 + 25) + "px; margin-left: -" + width/2 + "px;");
    return flep_request(page, post, headers, 'scrolable' + ld_id);
}
